<template>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-row>
	<el-col :span="12">
	    <el-form-item label="模块标题" prop="title">
	      <el-input v-model="dataForm.title" placeholder="模块标题"></el-input>
	    </el-form-item>
	</el-col>
	<el-col :span="12">
	    <el-form-item label="业务类型" prop="businessType">
	      <el-input v-model="dataForm.businessType" placeholder="业务类型"></el-input>
	    </el-form-item>
	</el-col>
	<el-col :span="12">
	    <el-form-item label="方法名称" prop="method">
	      <el-input v-model="dataForm.method" placeholder="方法名称"></el-input>
	    </el-form-item>
	</el-col>
	<el-col :span="12">
	    <el-form-item label="请求方式" prop="requestMethod">
	      <el-input v-model="dataForm.requestMethod" placeholder="请求方式"></el-input>
	    </el-form-item>
	</el-col>
	<el-col :span="12">
	    <el-form-item label="操作类别" prop="operType">
	      <el-input v-model="dataForm.operType" placeholder="操作类别"></el-input>
	    </el-form-item>
	</el-col>
	<el-col :span="12">
	    <el-form-item label="操作人员" prop="operName">
	      <el-input v-model="dataForm.operName" placeholder="操作人员"></el-input>
	    </el-form-item>
	</el-col>
	<el-col :span="12">
	    <el-form-item label="请求URL" prop="operUrl">
	      <el-input v-model="dataForm.operUrl" placeholder="请求URL"></el-input>
	    </el-form-item>
	</el-col>
	<el-col :span="12">
	    <el-form-item label="主机地址" prop="operIp">
	      <el-input v-model="dataForm.operIp" placeholder="主机地址"></el-input>
	    </el-form-item>
	</el-col>
	<el-col :span="12">
	    <el-form-item label="操作地点" prop="operLocation">
	      <el-input v-model="dataForm.operLocation" placeholder="操作地点"></el-input>
	    </el-form-item>
	</el-col>
	<el-col :span="12">
	    <el-form-item label="请求参数" prop="operParam">
	      <el-input v-model="dataForm.operParam" placeholder="请求参数"></el-input>
	    </el-form-item>
	</el-col>
	<el-col :span="12">
	    <el-form-item label="返回参数" prop="operResult">
	      <el-input v-model="dataForm.operResult" placeholder="返回参数"></el-input>
	    </el-form-item>
	</el-col>
	<el-col :span="12">
	    <el-form-item label="操作状态" prop="status">
	      <el-input v-model="dataForm.status" placeholder="操作状态"></el-input>
	    </el-form-item>
	</el-col>
	<el-col :span="12">
	    <el-form-item label="错误消息" prop="errMsg">
	      <el-input v-model="dataForm.errMsg" placeholder="错误消息"></el-input>
	    </el-form-item>
	</el-col>
	</el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import {addOrUpdate} from "@/api/system/sysoperlog";
  export default {
    data () {
      return {
      	title:'',
        visible: false,
        dataForm: {
          id: 0,
          title: '',
          businessType: '',
          method: '',
          requestMethod: '',
          operType: '',
          operName: '',
          operUrl: '',
          operIp: '',
          operLocation: '',
          operParam: '',
          operResult: '',
          operTime: '',
          status: '',
          errMsg: ''
        },
        dataRule: {
          title: [
            { required: true, message: '模块标题不能为空', trigger: 'blur' }
          ],
          businessType: [
            { required: true, message: '业务类型（0其它 1新增 2修改 3删除）不能为空', trigger: 'blur' }
          ],
          method: [
            { required: true, message: '方法名称不能为空', trigger: 'blur' }
          ],
          requestMethod: [
            { required: true, message: '请求方式不能为空', trigger: 'blur' }
          ],
          operType: [
            { required: true, message: '操作类别（0其它 1后台用户 2手机端用户）不能为空', trigger: 'blur' }
          ],
          operName: [
            { required: true, message: '操作人员不能为空', trigger: 'blur' }
          ],
          operUrl: [
            { required: true, message: '请求URL不能为空', trigger: 'blur' }
          ],
          operIp: [
            { required: true, message: '主机地址不能为空', trigger: 'blur' }
          ],
          operLocation: [
            { required: true, message: '操作地点不能为空', trigger: 'blur' }
          ],
          operParam: [
            { required: true, message: '请求参数不能为空', trigger: 'blur' }
          ],
          operResult: [
            { required: true, message: '返回参数不能为空', trigger: 'blur' }
          ],
          operTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '操作状态（0正常 1异常）不能为空', trigger: 'blur' }
          ],
          errMsg: [
            { required: true, message: '错误消息不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (record) {
        this.visible=true
        this.dataForm=record
        if(this.dataForm&&this.dataForm.id){
          this.title='操作日志记录'+'修改'
        }else{
          this.title='操作日志记录'+"新增"
        }
      },

      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
				addOrUpdate(this.dataForm).then(res=>{
					this.visible = false
				    this.$modal.msgSuccess(this.title+"成功");
            		this.$emit('refreshDataList')
				})
          }
        })
      }
    }
  }
</script>
